/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Color;
import java.awt.Graphics; 
import java.awt.image.BufferedImage;

/**
 *
 * @author chahine
 */
public class Logo_Panel extends javax.swing.JPanel {

    /**
     * Creates new form Logo_Panel
     */
    public Logo_Panel() {
        initComponents();
        //setOpaque(false); 
    
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

     
    static int i = 10;
     
    @Override
    public void paint(Graphics graphics){ 
  
         // super.paintComponent(graphics);
      /*    graphics.setColor(Color.red);
         if(i< 10000) graphics.drawRect(i, i, i, i);
         i++;         
 */
        paintComponent(graphics);
       }
    
    public  BufferedImage bi;
    Graphics g;
    public int curr_X,
                        curr_Y,
                        next_X,
                        next_Y,
                        dir = 0;
    
    public int temp_X , temp_Y ;
    public  boolean lock = true;
    public static boolean fast;
 
    private   boolean state;
    
    public  void reset()
    {
        lock = true;
        bi = null;
    }
    
    
      public void moveFast( int x, int penstate)
    {  
        if (bi == null){ 
        init_bi();      
    }  
        lock = true;
        curr_X = next_X;
        curr_Y = next_Y;
        next_X += x * Math.cos(Math.toRadians(dir));
        next_Y += x * Math.sin(Math.toRadians(dir));
        
        temp_X = next_X;
        temp_Y = next_Y;
        
        if(penstate==1) 
        	state = true;
        else 
        	state = false;
      }
    
    
    public   void move( int x, int penstate)
    {  
        if (bi == null){ 
        init_bi();      
    }  
        lock = true;
        curr_X = next_X;
        curr_Y = next_Y;
        next_X += x * Math.cos(Math.toRadians(dir));
        next_Y += x * Math.sin(Math.toRadians(dir));
        if(penstate==1) 
        	state = true;
        else 
        	state = false;
      }

    public   void turn (int x)
    {
        dir += x;
    }
    
   @Override 
   public void paintComponent(Graphics graphics){

    if (bi == null){ 
        init_bi();      
    }  
    computeNextPos();
    g.setColor((state) ? Color.black : Color.white);
    g.drawLine(curr_X, curr_Y, temp_X, temp_Y);
    graphics.drawImage(bi,0,0,null);
     
    graphics.setColor(Color.green);
    graphics.fillOval(temp_X - 20, temp_Y - 20, 40, 40);
    unlock();

  }
 
   private  void init_bi()
   {
      bi = new BufferedImage(getWidth(), getHeight(),BufferedImage.TYPE_INT_RGB);
      g = bi.createGraphics();
      g.setColor(Color.white); 
      g.fillRect(0, 0, getWidth(), getHeight());
           
      curr_X = this.getWidth() / 2;
      curr_Y = this.getHeight() / 2; 
      temp_X =  next_X = curr_X;
      temp_Y =  next_Y = curr_Y;
      dir = 0;        
      lock = true; 
      
   }
   
   private void computeNextPos()
   {
       if (temp_X < next_X) temp_X++;
       else if (temp_X > next_X) temp_X--;
       
       if (temp_Y < next_Y) temp_Y++;
       else if (temp_Y > next_Y) temp_Y--;
       
      /*
      if(temp_X != next_X)  temp_X  +=  Math.cos(dir * Math.PI / 180);
      if(temp_Y !=  next_Y)  temp_Y  +=  Math.sin(dir * Math.PI / 180);*/
   }
   
   

   
    public  void unlock()
    {       
      if((temp_X == next_X) && (temp_Y == next_Y)) 
      {
         lock=false;
      }
    }

  }

